<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/13
 * Time: 17:02
 */

namespace app\api\controller;

use app\api\model\Gz AS GzModel;
use app\api\model\Xl AS XhModel;
use app\api\validate\IdMustPositiveInteger;

class Gz extends Base
{
    /**
     * 故障列表
     * id      型号ID
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function gzList(){
        $xh_id = input('id');

        $result = (new IdMustPositiveInteger())->goCheck();
        if($result['status'] == 0) return json(['status' => 0, 'msg' => $result['msg']]);

        $XH = new XhModel();
        $whereXh['device_id'] = $xh_id;
        $fieldXh = 'device_gz';
        $_xh = $XH::findXl($whereXh, $fieldXh);

        $GZ = new GzModel();
        $where = [
            'gz_id' => ['IN', $_xh['device_gz']],
            'gz_status' => 1
        ];
        $field = 'gz_id, gz_name';
        $_gz = $GZ::selectGz($where, $field);
        if($_gz){
            return json(['status' => 200, 'msg' => $_gz]);
        }else{
            return json(['status' => 200, 'msg' => '']);
        }
    }
}